package servlet;

import dao.ProductDAO;
import entity.Product;
import org.bson.types.ObjectId;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "productGetId",value = "/product/getId")
public class ProdactGetIdServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String id = req.getParameter("id");
        System.out.println(id);
        ProductDAO dao = new ProductDAO();
        req.setAttribute("id",id);
        Product product=dao.findById(new ObjectId(id));
        req.setAttribute("pro",product);
        req.getRequestDispatcher("/product/Edit.jsp").forward(req, resp);
    }
}
